<?php
	$query = "select * from `radio_dj` where `userid`='$id'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)) {
		$djprofile = mysql_fetch_array($result);
		$dj_id = $djprofile['id'];


		if ($_REQUEST['delete']){
			$weekly_id = escapestr($_REQUEST['delete']);
			$query 	= "delete from `radio_weekly` where `id`='$weekly_id'";
			$result = mysql_query($query);
			if ($result) {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_weeklydeleted"),GetLangString($lang,"msg_weeklydeleted"));  
			} else {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror").$query);  
			}
		}
//--
		if ($_REQUEST['add']){


			$artist 	= escapestr($_REQUEST['artist']);
			$song =  escapestr($_REQUEST['song']);
			$week =  escapestr($_REQUEST['year'].$_REQUEST['week']);
						
			$query 	= "insert into `radio_weekly` (`artist`,`song`, `week`,`dj`) values ('$artist','$song','$week','$dj_id')";
			$result = mysql_query($query);
			if ($result) {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_weeklyadded"),GetLangString($lang,"msg_weeklyadded"));  
			} else {
				$SITE_MIDDLE .= FormatElement (GetLangString($lang,"txt_error"),GetLangString($lang,"msg_dberror").$query);  
			}
		}

//--


		$query 	= "select * from `radio_weekly` order by `week` asc";
		$result = mysql_query($query);
if ($result)
$txt = "<center><table border=\"1\" width=\"90%\"><tr>
			<td width=\"20%\">".GetLangString($lang,"txt_dj")."</td><td width=\"20%\">".GetLangString($lang,"txt_artist")."</td><td width=\"20%\">".GetLangString($lang,"txt_song")."</td><td width=\"20%\">".GetLangString($lang,"txt_week")."</td><td></td></tr>";

		while ($weekly = mysql_fetch_array($result)) {

			$artist 	= $weekly['artist'];
			$song			= $weekly['song'];
			$week  	=  	$weekly['week'];
			

			$query2 		= "select `name` from `radio_dj` where `id`=".$weekly['dj'];
			$result2 		= mysql_query ($query2) ; 
			$weekly_dj 	= mysql_result($result2,0);

			$ex	= $weekly['id'] ;
			$delete = "<a href=\"/index.php?do=djweekly&delete=$ex\">".GetLangString($lang,"txt_delete")."</a>"; 
			$txt .= "<tr><td>$weekly_dj</td><td>$artist</td><td>$song</td><td>$week</td><td>$delete</td></tr>";
		}
		$txt .= "</table>";
		$SITE_MIDDLE .= FormatElement(GetLangString ($lang,"txt_weeklysong"),$txt); 


		
		$frm = "<form action=\"/index.php?do=djweekly\" method=\"post\"><center><table style =\"padding: 0\" border=\"0\"><tr><td width=\"50%\">".
		FormatSmallElement( GetLangString ($lang, "txt_year") , "<input value=\"".date('Y')."\" name=\"year\" maxlenght=\"4\">").
		"</td><td width=\"50%\">".
		FormatSmallElement( GetLangString ($lang, "txt_week") , "<input value=\"".date('W')."\" name=\"week\" maxlenght=\"2\">").
		"</td></tr></table></center>".
			FormatSmallElement( GetLangString ($lang, "txt_artist") , "<input  name=\"artist\">").
			FormatSmallElement( GetLangString ($lang, "txt_song") , "<input  name=\"song\">").
		"<input name=\"add\" value=\"".GetLangString($lang,"txt_save")."\"type=\"submit\">";

		$SITE_MIDDLE .= FormatElement(GetLangString ($lang,"txt_addweekly"),$frm); 




	}else {
		$SITE_MIDDLE .= FormatElement(GetLangString($lang,"txt_error"),GetLangString($lang,"msg_nodjerror"));
	} 

?>
